today's article still about git and today we will discuss more making commit and reset commit with git. and the git platform I'll be using is gitlab.
Commit
before making a commit, we need to make initialize on a running project by simply run the following script:git init
before going to commit. I'm going to explain what is commit first, The "commit" command is used to save your changes to the local repository.
moving on with git commit. to commit a change, just simply run this three script:
$ git status
$ git add --filename
git commit -m "your message"
git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by git.
git add command adds new or changed files in your working directory to the Git staging area.
git commit -m "Add existing file" # Commits the tracked changes and prepares them to be pushed to a remote repository.
Undo Commit
git has three existing methods to undo commit or reset commit, there are checkout, revert, reset.
Let's say right now we are in the fifth commit like the image above, if someone wish to go back to the third commit, we may use checkout, revert, or reset depending on the situation.
git checkout if you wish to see your codes on third commit state, use checkout.
git revert command is a forward-moving undo operation that offers a safe method of undoing changes.
git reset when git reset is executed you, your Head will move back to the third commit and the remaining four and fifth commit will be removed as well. to perform reset you need to be considerate.